package com.jiaoyou.baojian.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jiaoyou.baojian.R;
import com.jiaoyou.baojian.entity.GiftEntity;
import com.jiaoyou.baojian.utils.Utils;

/**
 * Created by DemonZYM on 17/4/13.
 */

public class SendDialogGiftAdapter extends BaseQuickAdapter<GiftEntity, BaseViewHolder> {
    public SendDialogGiftAdapter() {
        super(R.layout.item_send_dialog_gift);
    }

    @Override
    protected void convert(BaseViewHolder helper, final GiftEntity item) {
        helper.setText(R.id.gift_name, item.getCandy() + "豆");
        Utils.showGiftImage(mContext, item.getImg(), (ImageView) helper.getView(R.id.gift_icon));
        ImageView sub = helper.getView(R.id.sub);
        TextView countText = helper.getView(R.id.count);
        ImageView add = helper.getView(R.id.add);

        if(item.count == 0){
            sub.setEnabled(false);
            countText.setText("0");
            countText.setTextColor(mContext.getResources().getColor(R.color.main_gray));
        } else {
            sub.setEnabled(true);
            countText.setText("" + item.count);
            countText.setTextColor(mContext.getResources().getColor(R.color.main_black_gray));
        }
        sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.count--;
                if(onGiftPriceChangeListener != null){
                    onGiftPriceChangeListener.OnGiftPriceChange(-item.getCandy());
                }
                notifyDataSetChanged();
            }
        });
        add.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                item.count++;
                if(onGiftPriceChangeListener != null){
                    onGiftPriceChangeListener.OnGiftPriceChange(item.getCandy());
                }
                notifyDataSetChanged();
            }
        });
    }

    private OnGiftPriceChangeListener onGiftPriceChangeListener;
    public void setOnGiftPriceChangeListener(OnGiftPriceChangeListener listener){
        onGiftPriceChangeListener = listener;
    }
    public interface OnGiftPriceChangeListener{
        void OnGiftPriceChange(int price);
    }
}
